Lab 6 - Data Maps, Interactive Graphs and Animations from the COVID-19 reporting data

Challenge Exercise 1

For the above graph “COVID-19 Deaths” summarize the counts for each Country on the graph and update the graph to 9/26/2020. You are doing some real life data wrangling. Data is not always in the form that you expected, so it is important to check what the results of each step are. You can summarize the counts for each country and find the median Lat and Long as a way of summarize the Lat and Long from each state. However, the US and several other countries do not have counts. This is because for some US (and other countries) the Lat and Long are NA. One strategies is to simply remove this data (which is fine for this class).

Using the mean or median(Lat) and (Long) is still not perfect. Some countries are still centered in the ocean. This is ok for ex1. You can use ggplotly to help trouble shoot by putting the Country_Region as text in the hover box

library(tidyverse)

daily_report <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>% 
  rename(Long = "Long_") %>%
  filter(Lat != "NA" & Long != "NA") %>%
  group_by(Country_Region) %>% 
  summarize(Lat = median(Lat),
            Long = median(Long),
            Deaths = sum(Deaths))
library(ggplot2)

plotly::ggplotly(
ggplot(data = daily_report, mapping = aes(x = Long, y = Lat, text = Country_Region, size = Deaths/1000)) + 
  borders("world", colour = NA, fill = "grey90") +
  theme_bw() +
  geom_point(shape = 21, color='purple', fill='purple', alpha = 0.5) +
  labs(title = 'COVID-19 Deaths',x = '', y = '', size="Deaths (x1000))") +
  theme(legend.position = "right") +
  coord_fixed(ratio=1.5)
)

Challenge Exercise 2

Update Anisa Dhana’s graph layout of the US to 9/26/2020. You may need to adjust the size of the points.

library(tidyverse)

daily_report <-   read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>% 
  rename(Long = "Long_") %>% 
  filter(Country_Region == "US") %>% 
  filter (!Province_State %in% c("Alaska","Hawaii", "American Samoa",
                  "Puerto Rico","Northern Mariana Islands", 
                  "Virgin Islands", "Recovered", "Guam", "Grand Princess",
                  "District of Columbia", "Diamond Princess")) %>% 
  filter(Lat > 0)
library(ggplot2)

mybreaks <- c(1, 100, 1000, 10000, 100000)

ggplot(daily_report, aes(x = Long, y = Lat, size = Confirmed)) +
  borders("state", colour = "white", fill = "grey90") +
  geom_point(aes(x=Long, y=Lat, size=Confirmed, color=Confirmed),stroke=F, alpha=0.7) +
  scale_size_continuous(name="Cases", trans="log", range=c(1,7), 
                        breaks=mybreaks, 
                        labels = c("1-99", "100-999", "1,000-9,999", "10,000-99,999", "100,000+")) +
  scale_color_viridis_c(option="viridis",name="Cases",
                        trans="log", breaks=mybreaks, 
                        labels = c("1-99", "100-999", "1,000-9,999", "10,000-99,999", "100,000+"))  +
  theme_void() + 
  guides(colour = guide_legend()) +
  labs(title = "COVID-19 Confirmed Cases in the US'") +
  theme(legend.position = "bottom",
        text = element_text(color = "#22211d"),
        plot.background = element_rect(fill = "#ffffff", color = NA), 
        panel.background = element_rect(fill = "#ffffff", color = NA), 
        legend.background = element_rect(fill = "#ffffff", color = NA),
        plot.title = element_text(face="bold", hjust=0.5)) +
  coord_fixed(ratio=1.5)
## Warning: Transformation introduced infinite values in discrete y-axis

## Warning: Transformation introduced infinite values in discrete y-axis
## Warning in sqrt(x): NaNs produced
## Warning: Removed 6 rows containing missing values (geom_point).

Challenge Exercise 3

Update the graph “Number of Confirmed Cases by US County” to 9/26/2020 and use a different color scheme or theme

library(tidyverse)

report_09_26_2020 <-   read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>% 
  rename(Long = "Long_") %>% 
  unite(Key, Admin2, Province_State, sep = ".") %>% 
  group_by(Key) %>% 
  summarize(Confirmed = sum(Confirmed)) %>% 
  mutate(Key = tolower(Key))

# get and format the map data
us <- map_data("state")
counties <- map_data("county") %>% 
  unite(Key, subregion, region, sep = ".", remove = FALSE)

# Join the 2 tibbles
state_join <- left_join(counties, report_09_26_2020, by = c("Key"))
options(scipen=999)

library(ggplot2)

ggplot(data = us, mapping = aes(x = long, y = lat, group = group)) + 
  coord_fixed(1.3) +
  borders("state", colour = "black") +
  geom_polygon(data = state_join, aes(fill = Confirmed)) +
  scale_fill_gradientn(colors = RColorBrewer::brewer.pal(n = 5, name = "BuPu"),
                       breaks = c(1, 10, 100, 1000, 10000, 100000, 1000000),
                       trans = "log10", na.value = "White") +
  ggtitle("Number of Confirmed Cases by US County") +
  theme_linedraw() +
  theme(panel.grid=element_blank(),
        plot.title=element_text(face="bold", hjust=0.5))
## Warning: Transformation introduced infinite values in discrete y-axis

Challenge Exercise 4

Make an interactive plot using a state of your chosing using a theme different from used in the above examples.

daily_report <-   read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>% 
  rename(Long = "Long_") %>% 
  filter(Province_State == "Washington") %>% 
  group_by(Admin2) %>% 
  summarize(Confirmed = sum(Confirmed)) %>% 
  mutate(Admin2 = tolower(Admin2))
us <- map_data("state")
wa_us <- subset(us, region == "washington")
counties <- map_data("county")
wa_county <- subset(counties, region == "washington")
state_join <- left_join(wa_county, daily_report, by = c("subregion" = "Admin2")) 
library(ggplot2)

plotly::ggplotly(
  ggplot(data = wa_county, mapping = aes(x = long, y = lat, group = group)) + 
  coord_fixed(1.3) + 
  geom_polygon(data = state_join, aes(fill = Confirmed), color = "black") +
    scale_fill_gradientn(colours = wesanderson::wes_palette("Royal1", 100, type = "continuous")) +
  ggtitle("COVID-19 Cases in WA") +
  labs(x=NULL, y=NULL) +
  theme(panel.border = element_blank()) +
  theme(panel.background = element_blank()) +
  theme(axis.ticks = element_blank()) +
  theme(axis.text = element_blank()) +
  theme(plot.title = element_text(face="bold"))
)

Challenge Exercise 5

Create a report with static maps and interactive graphs that is meant to be read by others (e.g. your friends and family). Hide warnings, messages and even the code you used so that it is readable. Included references. Link to the Lab 10 report from your Github site. Submit the link to Moodle. animations that is meant to be read by others (e.g. your friends and family). Hide warnings, messages and even the code you used so that it is readable. Included references. Link to the Lab 6 report from your Github site. Submit the link to Moodle.

You can find the link to this report on my Github site